package com.taoz.rpc.core.config;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;

public class ConfigLoader {
    public static <T> T loadConfig(Class<T> config, String prefix) {
        return loadConfig(config, prefix, "");
    }

    public static <T> T loadConfig(Class<T> config, String prefix, String environment) {
        StringBuilder fileName = new StringBuilder("application");
        if (StrUtil.isNotBlank(environment)) {
            fileName.append("-");
            fileName.append(environment);
        }
        fileName.append(".properties");
        Props props = new Props(fileName.toString());
        return props.toBean(config, prefix);
    }
}
